﻿/**************************************************************
* Copyright (C) 2022 www.eipflow.com 孙泽伟版权所有(盗版必究)
*
* 作者: 孙泽伟(QQ 1039318332)
* 创建时间: 2022/01/12 22:40:15
* 文件名: 
* 描述: 
* 
* 修改历史
* 修改人：
* 时间：
* 修改说明：
*
**************************************************************/

using EIP.Base.Models.Entities.System;
using EIP.Common.Core.Context;
using EIP.Common.Core.Util;
using EIP.Common.Logic;
using EIP.Common.Models;
using EIP.Common.Models.Dtos;
using EIP.Common.Models.Paging;
using EIP.Wms.Logic;
using EIP.Wms.Repository;
using EIP.WMS.Models.Dtos;

namespace EIP.Workflow.Logic.Impl
{
    /// <summary>
    /// 接口实现
    /// </summary>
    public class WmsTestLogic : DapperAsyncLogic<WmsTest>, IWmsTestLogic
    {
        #region 构造函数

        private readonly IWmsTestRepository _WmsTestRepository;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="WmsTestRepository"></param>
        public WmsTestLogic(IWmsTestRepository WmsTestRepository)
        {
            _WmsTestRepository = WmsTestRepository;
        }

        #endregion

        /// <summary>
        /// 根据Id删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<OperateStatus> Delete(IdInput<string> input)
        {
            OperateStatus operateStatus = new OperateStatus();
            foreach (var item in input.Id.Split(','))
            {
                operateStatus = await DeleteAsync(f => f.TestId == Guid.Parse(item));
            }
            return operateStatus;
        }

        /// <summary>
        /// 根据Id获取
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<OperateStatus<WmsTest>> FindById(IdInput input)
        {
            return OperateStatus<WmsTest>.Success(await FindAsync(f => f.TestId == input.Id));
        }

        /// <summary>
        /// 获取分页
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<OperateStatus<PagedResults<WmsTestFindOutput>>> Find(WmsTestFindInput input)
        {
            return OperateStatus<PagedResults<WmsTestFindOutput>>.Success(await _WmsTestRepository.Find(input));
        }

        /// <summary>
        /// 保存信息
        /// </summary>
        /// <param name="button">信息</param>
        /// <returns></returns>
        public async Task<OperateStatus> Save(WmsTest button)
        {
            var editButton = await FindAsync(f => f.TestId == button.TestId);
            var currentUser = EipHttpContext.CurrentUser();
            if (editButton != null)
            {
                button.Id = editButton.Id;
                return await UpdateAsync(button);
            }
            button.TestId = CombUtil.NewComb();
            return await InsertAsync(button);
        }
    }
}